package com.zmx.patientend.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.wang.adapters.adapter.BaseAdapterRvList;
import com.wang.adapters.base.BaseViewHolder;
import com.zmx.patientend.R;
import com.zmx.patientend.pojo.Evaluation;
import com.zmx.patientend.view.util.ViewStar;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 程序猿：胖胖祥
 * 时 间：2020/8/1  20:34
 * 功 能：
 */
public class EvaluationAdapter extends BaseAdapterRvList<EvaluationAdapter.ViewHolder, Evaluation> {

    public EvaluationAdapter(Activity activity) {
        super(activity);
    }

    @Override
    protected void onBindVH(ViewHolder holder, int listPosition, Evaluation evaluation) {

        holder.user.setText(evaluation.getName());
        holder.time.setText(evaluation.getPubtime());
        holder.context.setText(evaluation.getContent());
        Glide.with(mActivity).load(evaluation.getAvatar()).into(holder.user_head);

        float ratingCount = Float.parseFloat(evaluation.getTotalScore());

        if (ratingCount >= 80) {

            holder.ratingbar.setStar(5.0f);

        } else if (ratingCount >= 60 && ratingCount < 80) {

            holder.ratingbar.setStar(4.0f);

        } else if (ratingCount >= 40 && ratingCount < 60) {

            holder.ratingbar.setStar(3.0f);

        } else if (ratingCount >= 20 && ratingCount < 40) {

            holder.ratingbar.setStar(2.0f);

        } else if (ratingCount >= 0 && ratingCount < 20) {

            holder.ratingbar.setStar(1.0f);
        }

        holder.ratingbar.setClickable(false);

    }

    @NonNull
    @Override
    protected ViewHolder onCreateVH(ViewGroup parent, LayoutInflater inflater) {

        EvaluationAdapter.ViewHolder holder = new EvaluationAdapter.ViewHolder(inflater.inflate(R.layout.adapter_evaluation, parent, false));
        return holder;
    }

    static class ViewHolder extends BaseViewHolder {

        @BindView(R.id.user)
        TextView user;
        @BindView(R.id.context)
        TextView context;
        @BindView(R.id.user_head)
        CircleImageView user_head;
        @BindView(R.id.time)
        TextView time;
        @BindView(R.id.ratingbar)
        ViewStar ratingbar;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
